package com.cby.assist.Sample;

import android.app.ActivityManager;
import android.content.Context;

import com.cby.assist.kits.Category;
import com.cby.assist.kits.IKit;

import java.util.List;

/**
 * 描述信息
 *
 * @author 徐智伟
 * @create 2019/5/10
 */
public class RestartAppKit implements IKit {
  @Override
  public int getCategory() {
    return Category.CLOSE;
  }

  @Override
  public int getName() {
    return R.string.dev_restart;
  }

  @Override
  public int getIcon() {
    return R.mipmap.dk_crash_catch;
  }

  @Override
  public void onClick(Context context) {
    ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> mList = mActivityManager.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : mList) {
      if (runningAppProcessInfo.pid != android.os.Process.myPid()) {
        android.os.Process.killProcess(runningAppProcessInfo.pid);
      }
    }
    android.os.Process.killProcess(android.os.Process.myPid());
  }

  @Override
  public void onAppInit(Context context) {

  }
}
